<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">我的评论</block>
		</cu-custom>
		
		<view v-if="isInit">			
			
			<uniSticky>
				<navLongTab :tabTitle="tabs" @changeTab="changeTab"></navLongTab>
			</uniSticky>
			
			<view :style="'height:'+screenHeight+'px'">
				<mescroll-uni ref="mescrollRef" :fixed="false" top="0" :bottom="0"  @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback">
									
					<view v-show="tabNow==0">
						
						<mescroll-empty v-if="emptyList"></mescroll-empty>
										
						<view class="cu-card case" v-if="list.length>0">
							<!-- 评价部分 begin -->					
							<view class="cu-item shadow" v-for="(item,index) in list" :key="index">						
								<view  class="padding-sm solid-bottom padding-lr">								
									<commentSceneryItem @viewImage="showImageWin" @goDetail="goScenery(item.scenery.id)" @remove="refreshList" :is-user-list="true" :item="item"></commentSceneryItem>							
								</view>								
							</view>
							<!-- 评价部分 end -->
						</view>
					
					</view>
					
					<view v-show="tabNow==1">
						
						<mescroll-empty v-if="emptyList"></mescroll-empty>
										
						<view class="cu-card case" v-if="list.length>0">
							<!-- 评价部分 begin -->					
							<view class="cu-item shadow" v-for="(item,index) in list" :key="index">						
								<view class="padding-sm solid-bottom padding-lr">								
									<commentGoodsItem @viewImage="showImageWin" @goDetail="goGoods(item.goods.id)" @remove="refreshList" :is-user-list="true" :item="item"></commentGoodsItem>							
								</view>								
							</view>
							<!-- 评价部分 end -->
						</view>
					
					</view>
					
				</mescroll-uni>
			</view>
			
			<imageView :title="showImage.title" :avatar="showImage.avatar" :showModel="showImage.model" :imageIndex="showImage.index" :images="showImage.images" @closeWin="closeImageWin"></imageView>
		
		</view>
		<view class="cu-load load-modal" v-else-if="!isInit">
			<view class="gray-text">加载中...</view>
		</view>
		
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"; // 非uni_modules版本
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 非uni_modules版本
	import navLongTab from "@/components/tab/navLongTab.vue"
	import commentSceneryItem from '@/components/comment/comment-scenery-item.vue';
	import commentGoodsItem from '@/components/comment/comment-goods-item.vue';
	
	import imageView from '@/components/image-view/image-view.vue';
	import uniSticky from "@/uni_modules/uv-sticky/components/uv-sticky/uv-sticky.vue"
	
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			MescrollBody,commentSceneryItem,commentGoodsItem,imageView,navLongTab,uniSticky
		},
		data() {
			return {
				screenHeight:this.s_h_nob-70,
				bottomHeight:this.StatusBarBottom,
				sid:0,
				upOption: {
					page: {
						size: 6 // 每页数据的数量,默认10
					},
					empty: {
						tip: '暂无景点评价',
					},
					textNoMore:'-- 没有更多评价 --',
					toTop:{
						offset:200,
						bottom: '210rpx',
					}
				},
				isInit:false,
				list:[],
				showImage:{
					model:false,
					index:0,
					images:[],
					title:"",
					avatar:""
				},
				tabNow:0,
				tabs:[{name:'景点'},{name:'特产'}]
			}
		},
		onLoad() {
			setTimeout(()=>this.isInit=true,500)
		},
		methods: {
			changeTab(index){
				this.tabNow=index
				this.list=[]
				this.$nextTick(()=>{
					this.mescroll.resetUpScroll();
				})	
			},
			//页面数据请求事件
			upCallback(page) {
				let _this=this
				let pageNum = page.num; // 页码, 默认从1开始
				
				let params={
					"p":pageNum,
				}
						
				let url="/scenery/user_page_comment"
				if(this.tabNow==1){
					url="/goods/user_page_comment"
				}
				
				_this.$api.post(url,params).then(res => {
					let data=res.data;
					
					let curPageData = data.records;
					let curPageLen=curPageData.length
					let totalSize=data.total;
					
					if(page.num == 1) _this.list = []; //如果是第一页需手动置空列表
					_this.list = _this.list.concat(curPageData); //追加新数据
											
					_this.mescroll.endBySize(curPageLen, totalSize);
				})
			},
			refreshList(){
				this.list=[]
				this.$nextTick(()=>{
					this.mescroll.resetUpScroll();
				})
			},
			closeImageWin(){
				this.showImage.model=false
			},
			showImageWin(e){
				
				this.showImage.images=e.images
				this.showImage.index=e.now				
				this.showImage.title=e.title
				this.showImage.avatar=e.avatar
				
				this.showImage.model=true
			},
			goScenery(id){
				uni.navigateTo({
					url:"/pages/scenery/detail?id="+id
				})
			},
			goGoods(id){
				uni.navigateTo({
					url:'/pages/goods/detail?id='+id
				})
			}
		}		
	}
</script>

<style scoped>
</style>